
trait Person {
    fn new(some_name:String)->Self;
    fn say_hello(&self);
}
trait Teaching:Person {
    fn teaching(&self,course_name:&str);
}
struct Student {
    name:String,
    role: String 
}

struct Teacher {
    name:String,
    role: String 
}

impl Person for Teacher {
    fn new(some_name:String)->Self{
        Teacher {
            name:some_name,
            role:"Teacher".to_string()
        }
    }

    fn say_hello(&self) {
        println!("hello! I'm a {},My name is {}",&self.role,&self.name)
    }
}

impl Teaching for Teacher {
    fn teaching(&self,course_name:&str) {
        println!("I can teaching {}",course_name.to_string())
    }
}

impl Person for Student {
    fn new(some_name:String)->Self{
        Student {
            name:some_name,
            role:"Student".to_string()
        }
    }
    fn say_hello(&self) {
        println!("hello! I'm a {},My name is {}",&self.role,&self.name)
    }
}

pub fn main() {
    let teacher =  Teacher::new("alice".to_string());
    let student =  Student::new("bob".to_string());
    teacher.say_hello();
    teacher.teaching("English");
    call_teaching(teacher);
    student.say_hello();
}

// 泛型
fn call_teaching<T:Teaching>(a:T) {
    a.teaching("English");
}